package youcaihuaoa.weetop.com.ui.main

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.robot.base.base.activity.GLBaseActivity
import com.robot.base.configs.AppConstants
import youcaihuaoa.weetop.com.BR
import youcaihuaoa.weetop.com.R
import youcaihuaoa.weetop.com.databinding.AppActivityMessageGroupAddBinding
import youcaihuaoa.weetop.com.ui.adapter.MessageGroupAddAdapter
import youcaihuaoa.weetop.com.vm.main.MessageGroupAddViewModel

@Route(path = AppConstants.Router.Main.A_MESSAGE_GROUP_ADD)
class MessageGroupAddActivity :
    GLBaseActivity<AppActivityMessageGroupAddBinding, MessageGroupAddViewModel>() {
    override fun initContentView(savedInstanceState: Bundle?): Int =
        R.layout.app_activity_message_group_add

    override fun initVariableId(): Int = BR.viewModel

    private lateinit var messageGroupAddAdapter: MessageGroupAddAdapter
    override fun initComponents() {
        addSingleTitleBar("通讯录")
        messageGroupAddAdapter = MessageGroupAddAdapter().apply {
            setOnItemClickListener { adapter, view, position ->
                viewModel.ryimGroupUserJoin(messageGroupAddAdapter.data[position].id ?: "")
            }
        }
        binding.mRvGroup.apply {
            layoutManager = LinearLayoutManager(this@MessageGroupAddActivity)
            adapter = messageGroupAddAdapter
        }
        viewModel.ryimGetGroupData()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel.uiChangeEvent.dataEvent.observe(this) {
            messageGroupAddAdapter.setList(it)
        }
    }
}